var monitor = (function(){
    function bind(b){
        var queue = this.__MSG_QS__=this.__MSG_QS__ || {};
        if(!queue[b]){
            queue[b]=[]
        }
        for(var a = 1,X = arguments.length, Y;a<X;a++){
            queue[b].push(arguments[a]);
        }
        // console.error("bind",b,this.__MSG_QS__)
    }

    function unBind(a){
        var qs=this.__MSG_QS__ || {};
        var sqs=this.__STATIC_MSG_QS__ || {};
        for(var b=1,X=arguments.length,Y;b<X;b++){
            for(var key in qs){
                if(key ==a && qs[key]){
                    var loop = qs[key].length
                    for(var i = 0;i<loop;i++){
                        if(qs[key][i]===arguments[b]){
                            var deletObj =qs[key].splice(i,1)
                            i=i-1;
                            loop=loop-1;
                        }
                    }
                }
            }
        }
        if(arguments.length==1){
            for(var key in qs){
                if(key==a){
                    qs[key]=null;
                }
            }
            for(var key in sqs){
                if(key==a){
                    sqs[key]=null;
                }
            }
        }
        // console.error("unbind",a,this.__MSG_QS__,this.__STATIC_MSG_QS__)
    }
    function live(b){
        var queue = this.prototype.__STATIC_MSG_QS__;
        if(!queue[b]){
            queue[b]=[]
        }
        for(var a=1,X=arguments.length,Y;a<X;a++){
            queue[b].push(arguments[a]);
        }
    }
    function trigger(Y){
        var queue =[];
        var qs=this.__MSG_QS__ || {};
        var sqs=this.__STATIC_MSG_QS__ || {};
        if(Y.type == "109"){
            // console.log("trigger 109 event ",qs,qs[Y.type])
        }
        queue = queue.concat(qs[Y.type] || []);
        queue = queue.concat(sqs[Y.type] || []);
        // console.error("trigger",Y,queue,qs)
        for(var a = 0,X=queue.length; a < X; a++){
            if(queue[a].handler){
                queue[a].handler(Y,this)
            }else{
                queue[a].call(this,Y,this)
            }
        }
    }


    return {
        ini:function(X){
            
            if(Object.prototype.toString.call(X)=="[object Function]"){
                var proto=X.prototype;
                proto.__STATIC_MSG_QS__={};
                proto.bind = bind;
                proto.unBind = unBind;
                proto.trigger = trigger;
                X.live = live;
            }
            X.bind = bind;
            X.unBind = unBind;
            X.trigger = trigger;
            // console.error("aaa",X)
            return X;
        }
    }
})();

function CustomEventSystem(){

}

(function(){
    var eventSystem = monitor.ini(CustomEventSystem)
    var eventManager = new eventSystem();
    window.CustomEventManager = eventManager;
})()
// console.log("sssssssss",window.CustomEventManager)
// module.exports = eventManager;